package com.bwie.home.backstage.controller;

import java.util.Arrays;
import java.util.Map;

import com.bwie.home.backstage.aop.Token;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.bwie.home.backstage.entity.TeambuyEntity;
import com.bwie.home.backstage.service.TeambuyService;
import com.bwie.home.common.utils.PageUtils;
import com.bwie.home.common.utils.R;



/**
 * 
 *
 * @author sy
 * @email sunlightcs@gmail.com
 * @date 2021-09-16 11:01:32
 */
@RestController
@RequestMapping("backstage/teambuy")
public class TeambuyController {
    @Autowired
    private TeambuyService teambuyService;

    /**
     * 获取当前团购列表（展示已结束的（未逻辑删除状态），按时间倒序排序）
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = teambuyService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		TeambuyEntity teambuy = teambuyService.getById(id);

        return R.ok().put("teambuy", teambuy);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TeambuyEntity teambuy){
		teambuyService.save(teambuy);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody TeambuyEntity teambuy){
		teambuyService.updateById(teambuy);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		teambuyService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 开启/关闭团购状态
     */
    @PutMapping("/utb/{status}")
    public R updateTeamBuy(@PathVariable int status){
        return teambuyService.updateTeamBuy(status);

    }

    /**
     * 获取当前团购状态
     */
    @GetMapping("/gtb")
    public R getTeamBuy(){
        int status=teambuyService.getTeamBuy();

        return R.ok().put("status",status);
    }

    /**
     * 删除对应的团购列表(逻辑删除)
     */
    @PutMapping("/delTeamBuy")
    public R dtb(@RequestBody Integer[] ids){
        teambuyService.dtb(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 开启/关闭拼团状态
     */
    @PutMapping("/uptb/{status}")
    public R updatePinTeamBuy(@PathVariable int status){
        return teambuyService.updatePinTeamBuy(status);
    }

    /**
     * 获取当前经纪人的拼团状态
     */
    @GetMapping("/gptb")
    public R getPinTeamBuy(){
        int status=teambuyService.getPinTeamBuy();

        return R.ok().put("status",status);
    }




}
